package com.larry.rabbitmq.third;

import com.larry.rabbitmq.util.RabbitMQUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Properties;
import java.util.Scanner;

/**
 * @author larry
 * @Title: larry-rabbitmq
 * @Package com.larry.rabbitmq.third
 * @Description: 消息在手动应答时不丢失,并重新放回队列
 * @date 6/28/2111:22 PM
 */
public class Task02 {

    //队列名称
    public static final String TASK_QUEUE_NAME = "ack_queue";

    public static void main(String args[]) throws Exception{
        Channel channel = RabbitMQUtils.getChannel();

        //声明队列
        channel.queueDeclare(TASK_QUEUE_NAME,false,false,false,null);

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String message = scanner.next();
//            channel.basicPublish("",TASK_QUEUE_NAME,null,message.getBytes("UTF-8"));
            //设置生产者发送消息为持久化(保存在磁盘中)  也可能丢失
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes("UTF-8"));
            System.out.println("生产者发出消息........ " + message);
        }

    }
}
